//
//  myDetailVC.m
//  HappyStore
//
//  Created by 陈锋 on 16/6/6.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "myDetailVC.h"
#import "HeadView.h"
#import "hobbyCell.h"
#import "workCell.h"
#import "detailProfile.h"
#import "addJobVC.h"
#import "companyProfileFirCell.h"
#import "companyProfileSecCell.h"
#import "companyMyProfileCell.h"
#import "PersonProfileCell.h"

#import "ExperienceVC.h"

#import "FriendViewController.h"

@interface myDetailVC (){
    NSMutableArray* hobbyArr;
    NSMutableArray *dataArr;
    NSDictionary * pageDict;
}
@property (strong, nonatomic) NSArray * dataArr;
@property (strong, nonatomic) NSArray * educationArr;
@property (strong, nonatomic) HeadView *headView;
@end


static NSString * personProfilecell = @"personProfilecell";
static NSString * hobbycell = @"hobbyCell";
static NSString * workcell = @"workCell";
static NSString * companyProfileFircell = @"companyProfileFirCell";
static NSString * companyProfileSeccell = @"companyProfileSecCell";
static NSString * companyMyProfilecell = @"companyMyProfileCell";
@implementation myDetailVC

- (HeadView *)headview{
    if (!_headView) {
        _headView = [[[NSBundle mainBundle] loadNibNamed:@"HeadView" owner:self options:nil] lastObject];
    }
    return _headView;
}

-(NSArray *)educationArr{
    if (!_educationArr) {
        _educationArr = [NSArray array];
    }
    return _educationArr;
}
-(NSArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSArray array];
    }
    return _dataArr;
}

-(NSMutableDictionary *)dicData{
    if (!_dicData) {
        _dicData = [NSMutableDictionary dictionary];
    }
    return _dicData;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.translucent = NO;
    //找出导航栏的下边的黑线
    UIImageView *navBarHairlineImageView = [NaviBarLine findHairlineImageViewUnder:self.navigationController.navigationBar];
    navBarHairlineImageView.hidden = NO;
    navBarHairlineImageView.alpha = 0.5f;
    // 设置头视图
    [self setData];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.translucent = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.tabBarController.tabBar.hidden = YES;
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"个人详情";
    titleLabel.textColor = RGB(45, 45, 45);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    //self.title = @"个人详情";
    // 注册
    UINib * nib1 = [UINib nibWithNibName:@"PersonProfileCell" bundle:nil];
    [self.tableView registerNib:nib1 forCellReuseIdentifier:personProfilecell];
    
    UINib * nib2 = [UINib nibWithNibName:@"hobbyCell" bundle:nil];
    [self.tableView registerNib:nib2 forCellReuseIdentifier:hobbycell];
    
    UINib * nib3 = [UINib nibWithNibName:@"workCell" bundle:nil];
    [self.tableView registerNib:nib3 forCellReuseIdentifier:workcell];
    
    UINib * nib4 = [UINib nibWithNibName:@"companyProfileFirCell" bundle:nil];
    [self.tableView registerNib:nib4 forCellReuseIdentifier:companyProfileFircell];
    
    UINib * nib5 = [UINib nibWithNibName:@"companyProfileSecCell" bundle:nil];
    [self.tableView registerNib:nib5 forCellReuseIdentifier:companyProfileSeccell];
    
    UINib *nib6 = [UINib nibWithNibName:@"companyMyProfileCell" bundle:nil];
    [self.tableView registerNib:nib6 forCellReuseIdentifier:companyMyProfilecell];
    
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemClick)];
    rightItem.tintColor = RGB(45, 45, 45);
    self.navigationItem.rightBarButtonItem = rightItem;
    
    [self sendRequest];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}

-(void)rightBarButtonItemClick{
    detailProfile * detailProfileVC = [[detailProfile alloc]init];
    detailProfileVC.dataDict = [NSMutableDictionary dictionaryWithDictionary:self.dicData];
    detailProfileVC.workArr = [self.dataArr copy];
    detailProfileVC.eduArr = [self.educationArr copy];
    [self.navigationController pushViewController:detailProfileVC animated:YES];
}

-(void)leftBarButtonItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人
        
        return 4;
    }else if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 2) {//企业
        
        return 3;
        
    }else return 0;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人
        
        if (section == 0) {
            return 1;
        }else if(section == 1){
            return 1;
        }else if (section == 2)
        {
            return self.dataArr.count;
        }else if(section == 3){
            return self.educationArr.count;
        }
        else return 0;
        
    }else if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 2) {//企业
        
        return 1;
        
    }else return 0;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
//    int a = [[USER_DEFAULTS objectForKey:@"usertype"] integerValue];
    if (indexPath.section == 0) {
        if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {
         

            PersonProfileCell * profileCell = [self.tableView dequeueReusableCellWithIdentifier:personProfilecell];
            
            if (pageDict) {
                
                profileCell.classBtn.hidden = NO;
                profileCell.classCount.text = [NSString stringWithFormat:@"%ld",[pageDict[@"sumCount"]integerValue]];
                profileCell.classTitle.text = dataArr[0][@"content"];
                profileCell.classTime.text = dataArr[0][@"createTime"];
                if ([dataArr[0][@"photos"][0] isEqualToString:Default_Image]) {
                    profileCell.classImgConstraint.constant = 0;
                }else{
                    [profileCell.classImg sd_setImageWithURL:[NSURL URLWithString:dataArr[0][@"photos"][0]]];
                }
                [profileCell.classBtn addTarget:self action:@selector(jumpClass) forControlEvents:UIControlEventTouchUpInside];
                
            }
            
            if ([self.dicData[@"signature"] isEqualToString:@""] || [self.dicData[@"signature"] isEqualToString:@"null"]) {
                
                profileCell.myprofile.text = @"暂无简介";
                
            }else{
                
                profileCell.myprofile.text = self.dicData[@"signature"];
                
            }
            
            if ([self.dicData[@"goodatfield"] isEqualToString:@""] || [self.dicData[@"goodatfield"] isEqualToString:@"null"]) {
                
                profileCell.focus.text = @"暂无关注领域";
                
            }else{
                
                profileCell.focus.text = self.dicData[@"goodatfield"];
                
            }
            
            if ([self.dicData[@"myneeds"] isEqualToString:@""] || [self.dicData[@"myneeds"] isEqualToString:@"null"]) {
                
                profileCell.needs.text = @"暂无需求";
                
            }else{
                
                profileCell.needs.text = self.dicData[@"myneeds"];
                
            }
            
            
            return profileCell;
        

        }else if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 2) {//企业
            
            companyProfileFirCell * companyProfileFir = [self.tableView dequeueReusableCellWithIdentifier:companyProfileFircell];
    
            if ([self.dicData[@"introduction"] isEqualToString:@"null"] || [self.dicData[@"introduction"] isEqualToString:@""]) {
                
                companyProfileFir.detailLabel.text = @"暂未填写";
                
            }else{
            
                companyProfileFir.detailLabel.text = self.dicData[@"introduction"];
                [companyProfileFir.detailLabel setNumberOfLines:0];
            
            }
            
            
            return companyProfileFir;
        }else return nil;
 
    }else if (indexPath.section == 1){
        
        if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人
            

            hobbyCell * hobbyCell = [self.tableView dequeueReusableCellWithIdentifier:hobbycell];
            
            
            if ([self.dicData[@"hobby"] isEqualToString:@""] || [self.dicData[@"hobby"] isEqualToString:@"null"]) {
                
            }else{
                
                for (int i = 0; i < hobbyArr.count; i++) {
                    
                    if (i != hobbyArr.count -1 && i != hobbyArr.count) {
                        
                        UILabel *label =  hobbyCell.hobby[i];
                        //label.layer.masksToBounds = YES;
                        label.layer.borderColor = [UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f].CGColor;
                        label.layer.borderWidth = 0.5f;
                        //label.layer.cornerRadius = 5.0f;
                        label.backgroundColor = [UIColor colorWithRed:210.0/255.0f green:244.0/255.0f blue:255.0/255.0f alpha:1.0f];
                        label.textColor = [UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f];
                        label.text = hobbyArr[i];
                    }
                    
                }
                
                
            }
            
            return hobbyCell;
            
        }else if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 2) {//企业
            
            companyMyProfileCell * ProfileCell = [self.tableView dequeueReusableCellWithIdentifier:companyMyProfilecell];
            
            if (pageDict) {
                
                ProfileCell.classBtn.hidden = NO;
                ProfileCell.classCount.text = [NSString stringWithFormat:@"%d",[pageDict[@"sumCount"]integerValue]];
                ProfileCell.classTitle.text = dataArr[0][@"content"];
                ProfileCell.classTime.text = dataArr[0][@"createTime"];
                [ProfileCell.classImg sd_setImageWithURL:[NSURL URLWithString:dataArr[0][@"photos"][0]]];
                [ProfileCell.classBtn addTarget:self action:@selector(jumpClass) forControlEvents:UIControlEventTouchUpInside];
                
            }
    
            
            if ([self.dicData[@"companyField"] isEqualToString:@""] || [self.dicData[@"companyField"] isEqualToString:@"null"]) {
                
                ProfileCell.focus.text = @"暂无关注领域";
                
            }else{
                
                ProfileCell.focus.text = self.dicData[@"companyField"];
                
            }
            
            if ([self.dicData[@"companyBusNeeds"] isEqualToString:@""] || [self.dicData[@"companyBusNeeds"] isEqualToString:@"null"]) {
                
                ProfileCell.needs.text = @"暂无需求";
                
            }else{
                
                ProfileCell.needs.text = self.dicData[@"companyBusNeeds"];
                
            }
            
            return ProfileCell;
            
        }else return nil;
    
        
    
    }else if (indexPath.section == 2){
        if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人

            
            workCell * workCell = [self.tableView dequeueReusableCellWithIdentifier:workcell];
            NSDictionary * dict = self.dataArr[indexPath.row];
            [workCell.workImg setImage:[UIImage imageNamed:@"职业经历(1)"]];
            //[workCell.workImg sd_setImageWithURL:[NSURL URLWithString:dict[@"workLogo"]]];
            [workCell.workImg.layer setCornerRadius:(workCell.workImg.frame.size.height/2)];
            [workCell.workImg.layer setMasksToBounds:YES];
            [workCell.workImg setContentMode:UIViewContentModeScaleAspectFill];
            [workCell.workImg setClipsToBounds:YES];
            workCell.workImg.layer.shadowColor = [UIColor whiteColor].CGColor;
            workCell.workImg.layer.shadowOffset = CGSizeMake(4, 4);
            workCell.workImg.layer.shadowOpacity = 0.5;
            workCell.workImg.layer.shadowRadius = 2.0;
            
            workCell.position.text = dict[@"workPosition"];
            workCell.company.text = dict[@"workName"];
            workCell.workTime.text = dict[@"workTime"];
            
            workCell.img1.image = [UIImage imageNamed:@"btn_myD_gz1"];
            workCell.img2.image = [UIImage imageNamed:@"btn_myD_gz2"];
            workCell.img3.image = [UIImage imageNamed:@"btn_myD_gz3"];
            
            return workCell;
            
        }else if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 2) {//企业
            companyProfileSecCell * companyProfileSec = [self.tableView dequeueReusableCellWithIdentifier:companyProfileSeccell];
            
            if ([self.dicData[@"companyNature"] isEqualToString:@"null"] || [self.dicData[@"companyNature"] isEqualToString:@""]) {
                
                companyProfileSec.xingZhi.text = @"暂未添加";
            }else{
            
                companyProfileSec.xingZhi.text = self.dicData[@"companyNature"];
            
            }
            if ([self.dicData[@"companyIndustry"] isEqualToString:@"null"] || [self.dicData[@"companyIndustry"] isEqualToString:@""]) {
                
                companyProfileSec.hangYe.text = @"暂未添加";
            }else{
                
                companyProfileSec.hangYe.text = self.dicData[@"companyIndustry"];
                
            }
            if ([self.dicData[@"companyScale"] isEqualToString:@"null"] || [self.dicData[@"companyScale"] isEqualToString:@""]) {
                
                companyProfileSec.guiMo.text = @"暂未添加";
            }else{
                
                companyProfileSec.guiMo.text = self.dicData[@"companyScale"];
                
            }
            if ([self.dicData[@"companyWWW"] isEqualToString:@"null"] || [self.dicData[@"companyWWW"] isEqualToString:@""]) {
                
                companyProfileSec.wangZhan.text = @"暂未添加";
            }else{
                
                companyProfileSec.wangZhan.text = self.dicData[@"companyWWW"];
                
            }
            return companyProfileSec;
            
        }else return nil;

    
    }else if (indexPath.section == 3){

        workCell * workCell = [self.tableView dequeueReusableCellWithIdentifier:workcell];
        NSDictionary * dict = self.educationArr[indexPath.row];
        [workCell.workImg setImage:[UIImage imageNamed:@"教育经历(1)"]];
        //[workCell.workImg sd_setImageWithURL:[NSURL URLWithString:dict[@"schoolLogo"]]];
        [workCell.workImg.layer setCornerRadius:(workCell.workImg.frame.size.height/2)];
        [workCell.workImg.layer setMasksToBounds:YES];
        [workCell.workImg setContentMode:UIViewContentModeScaleAspectFill];
        [workCell.workImg setClipsToBounds:YES];
        workCell.workImg.layer.shadowColor = [UIColor whiteColor].CGColor;
        workCell.workImg.layer.shadowOffset = CGSizeMake(4, 4);
        workCell.workImg.layer.shadowOpacity = 0.5;
        workCell.workImg.layer.shadowRadius = 2.0;
        
        workCell.position.text = dict[@"schoolStudy"];
        workCell.company.text = dict[@"schoolName"];
        workCell.workTime.text = dict[@"schoolTime"];
        
        workCell.img1.image = [UIImage imageNamed:@"btn_myD_jy1"];
        workCell.img2.image = [UIImage imageNamed:@"btn_myD_jy2"];
        workCell.img3.image = [UIImage imageNamed:@"btn_myD_gz3"];
        
        return workCell;
    

    }
    
    
    else return  nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];//取消选中状态
    
    if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人
        if (indexPath.section == 2) {//修改工作经历
            ExperienceVC *educationVC = [[ExperienceVC alloc] init];
            educationVC.tigStr = @"1";
            educationVC.oldExperienceDic = self.dataArr[indexPath.row];
            [self.navigationController pushViewController:educationVC animated:YES];
        }else if (indexPath.section == 3){//修改教育经历
            ExperienceVC *educationVC = [[ExperienceVC alloc] init];
            educationVC.tigStr = @"2";
            educationVC.oldExperienceDic = self.educationArr[indexPath.row];
            [self.navigationController pushViewController:educationVC animated:YES];
        }
    }
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人
        
        if (indexPath.section == 0) {
            //个人简介
            UILabel *label = [[UILabel alloc] init];
            label.numberOfLines = 0;
            if (!self.dicData[@"signature"]) {
                label.text = @"暂无简介";
            }else{
                label.text = self.dicData[@"signature"];
            }
            label.font = [UIFont systemFontOfSize:14];
            CGSize size = [label sizeThatFits:CGSizeMake(228, MAXFLOAT)];
            //商务需求
            UILabel *needLabel = [[UILabel alloc] init];
            needLabel.numberOfLines = 0;
            if (!self.dicData[@"myneeds"]) {
                needLabel.text = @"暂无关注领域";
            }else{
                needLabel.text = self.dicData[@"myneeds"];
            }
            needLabel.font = [UIFont systemFontOfSize:14];
            CGSize needSize = [needLabel sizeThatFits:CGSizeMake(228, MAXFLOAT)];
            
            return 130 +size.height +needSize.height;
        }else if (indexPath.section ==1 ){
            return 80;
        }else if (indexPath.section == 2){
            return 80;
        }else if (indexPath.section == 3){
            return 80;
        }
        else return 0;

    }else if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 2) {//企业
        
        if (indexPath.section == 0) {
            companyProfileFirCell * companyProfileFir = [self tableView:tableView cellForRowAtIndexPath:indexPath];
            //设置字体
            UIFont *font = [UIFont fontWithName:@"Arial" size:14];
            companyProfileFir.detailLabel.font = font;
            
            CGSize constraint = CGSizeMake(250, 9999.0f);
            
            CGSize size = [companyProfileFir.detailLabel.text sizeWithFont:font constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
            
            [companyProfileFir.detailLabel setFrame:CGRectMake(0, 0, size.width, size.height)];
            
            //设置cell自适应高度
            CGRect cellFrame = [companyProfileFir frame];
            cellFrame.origin = CGPointMake(0, 0);
            CGFloat totalHeight = cellFrame.size.height + companyProfileFir.detailLabel.height - 40;
            cellFrame.size.height = totalHeight;
            [companyProfileFir setFrame:cellFrame];
            
            return companyProfileFir.frame.size.height ;
            
        }else if (indexPath.section ==1 ){
            companyMyProfileCell *comCell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
            CGSize size = [comCell.needs sizeThatFits:CGSizeMake(228, MAXFLOAT)];
            return comCell.frame.size.height + size.height -20;
        }else if (indexPath.section == 2){
            return 150;
        }else return 0;
        
    }else return 0;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 2) {
        if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 2) {//企业
            return 10;
        }else{
        return 40;
        }
    }else if (section == 3){
        return 40;
    }else
    return 10;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableView.width, 40)];
        view.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:247.0/255.0];
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(5, 2, 60, 25)];
        label.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:247.0/255.0];
        label.textColor = [UIColor lightGrayColor];
        label.font = [UIFont systemFontOfSize:14];
        
        
        if (section == 2) {
            UIButton * addBtn = [[UIButton alloc]initWithFrame:CGRectMake(view.width - 40, 2, 25, 25)];
            [addBtn setImage:[UIImage imageNamed:@"tianjia"] forState:0];
            [addBtn addTarget:self action:@selector(addwork) forControlEvents:UIControlEventTouchUpInside];
            label.text = @"职业经历";
            [view addSubview:addBtn];
            [view addSubview:label];
            return view;
            
        }else if (section == 3){
            UIButton * addBtn = [[UIButton alloc]initWithFrame:CGRectMake(view.width - 40, 2, 25, 25)];
            [addBtn setImage:[UIImage imageNamed:@"tianjia"] forState:0];
            [addBtn addTarget:self action:@selector(addeducation) forControlEvents:UIControlEventTouchUpInside];
            label.text = @"教育经历";
            [view addSubview:addBtn];
            [view addSubview:label];
            return view;
            
        }else return nil;
    }
    
   else

    
    return nil;
}
#pragma mark - 添加工作经历／教育经历
-(void)addwork{
    ExperienceVC *educationVC = [[ExperienceVC alloc] init];
    educationVC.tigStr = @"3";
    [self.navigationController pushViewController:educationVC animated:YES];
//    addJobVC * addJob = [[addJobVC alloc]init];
//    addJob.titleStr = @"工作经历";
//    [self.navigationController pushViewController:addJob animated:YES];
}
-(void)addeducation{
    
    ExperienceVC *educationVC = [[ExperienceVC alloc] init];
    educationVC.tigStr = @"4";
    [self.navigationController pushViewController:educationVC animated:YES];
//    addJobVC * addJob = [[addJobVC alloc]init];
//    addJob.titleStr = @"教育经历";
//    [self.navigationController pushViewController:addJob animated:YES];
}
//侧滑－－删除
//先要设Cell可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2 || indexPath.section == 3) {
        return YES;
    }else return NO;
}

//定义编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

//进入编辑模式，按下出现的编辑按钮后
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2) {
        NSDictionary * dict = self.dataArr[indexPath.row];
        [self startDeleteWithId:indexPath withType:2 muDicParameters:dict];
    
    }else if (indexPath.section == 3){
        NSDictionary * dict = self.educationArr[indexPath.row];
        [self startDeleteWithId:indexPath withType:1 muDicParameters:dict];
        
    }

}

//修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}
#pragma mark - 删除数据
- (void)startDeleteWithId:(NSIndexPath *)indexPath withType:(NSInteger)deType muDicParameters:(NSDictionary *)muDicParameter
{
    [self showRoundProgressWithTitle:@"删除中..."];
    
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    
    
    NSString *strURl;

    if (deType == 1) {//教育
        strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"deletePeopleEducation_app_myHome.im.lensum"];
        
        [muDicParameters setObject:muDicParameter[@"schoolName"] forKey:@"schoolName"];//学校名称
    }else {//工作
        strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"deletePeopleWork_app_myHome.im.lensum"];
        
        [muDicParameters setObject:muDicParameter[@"workName"] forKey:@"workName"];//公司名称
    }
    
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        NSLog(@"%@",dicInfo);
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            if (deType == 1) {//教育
                [self setData];
            }else {//工作
                [self setData];
            }
            
            self.tableView.contentSize = CGSizeMake(0, self.tableView.contentSize.height + 20);
           
        }else {

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
            
        }

        [self hideBubble];

        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
}
-(void)setData{
    self.headView = [[[NSBundle mainBundle] loadNibNamed:@"HeadView" owner:self options:nil] lastObject];
    
    //token=rE3F2m8AvfC7CVh85O9q&userId=9&userType=用户类型 1-个人，2-企业，3-政府
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"usertype"] forKey:@"userType"];//用户类型 1-个人，2-企业，3-政府
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"MyBasicMessage_app_myHome.im.lensum"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        //        NSLog(@"%@",dicInfo);
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            _dicData = dicInfo[@"data"];
            
            [self.headView.imgStr sd_setImageWithURL:[NSURL URLWithString:_dicData[@"headPhoto"]]];
            
        
            if (_dicData[@"userName"] == [NSNull null] || [_dicData[@"userName"] isEqualToString:@"null"]) {

                self.headView.nameStr.text = _dicData[@"account"];
                
            }else {

                self.headView.nameStr.text = _dicData[@"userName"];
                            }
            
            if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人

                //positionName-
                //goveAccount 政府账户
                //companyAccount 企业帐户
                
                if (_dicData[@"positionName"] == [NSNull null] || [_dicData[@"positionName"] isEqualToString:@"null"]) {
                    self.headView.positionNameStr.text = @"";
                }else {
                    self.headView.positionNameStr.text = _dicData[@"positionName"];
                    
                }
                //封装判断好的上级
                self.headView.companyUserNameStr.text = [UsedTool userType:@"1" companyName:self.dicData[@"companyName"] userAddress:self.dicData[@"address"]];
            }else if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 2) {//企业
                //positionName-
                //goveAccount 政府账户
                //companyAccount 企业帐户
                
                if (_dicData[@"userName"] == [NSNull null] || [_dicData[@"userName"] isEqualToString:@"null"]) {
          
                    self.headView.nameStr.text = _dicData[@"account"];
                 
                }else {
                    self.headView.nameStr.text = _dicData[@"userName"];
                }
                
                
                self.headView.positionNameStr.text = @"";
             
//                if (_dicData[@"companyAccount"] == nil || [_dicData[@"companyAccount"] isEqualToString:@""]||[_dicData[@"companyAccount"] isEqualToString:@"null"]) {
//                    //没上级
//                    self.headView.companyUserNameStr.text = _dicData[@"address"];
//                }else{
//                    if (_dicData[@"companyUserName"]==nil ||[_dicData[@"companyUserName"] isEqualToString:@""]||[_dicData[@"companyUserName"] isEqualToString:@"null"]) {
//                        self.headView.companyUserNameStr.text = _dicData[@"companyAccount"];
//                    }else{
//                        self.headView.companyUserNameStr.text = _dicData[@"companyUserName"];
//                    }
//                    
//                }
               
                //封装判断好的上级
                self.headView.companyUserNameStr.text = [UsedTool userType:@"2" companyName:nil userAddress:self.dicData[@"address"]];
                
            }else if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 3) {//政府
                
                self.headView.companyUserNameStr.text = _dicData[@"address"];
        
                
            }
            
//            if ([_dicData[@"authState"] integerValue] == 2) {
//                self.headView.vStr.image = [UIImage imageNamed:@"yirenzheng"];
//            }else{
//                self.headView.vStr.image = [UIImage imageNamed:@"weirenzheng"];
//            }
            //认证
            self.headView.isAuthState.hidden = [UsedTool authStateImageViewHidden:_dicData[@"authState"]];
            //会员图标
            self.headView.vStr.image = [UsedTool setVipimage:_dicData[@"vipLevel"]];
            if ([_dicData[@"mobile"] isEqualToString:@"null"] || [_dicData[@"mobile"] isEqualToString:@""]) {
                
                self.headView.phoneStr.text = @"暂未添加";
            }else{
                self.headView.phoneStr.text = _dicData[@"mobile"];
            }
            if ([_dicData[@"email"] isEqualToString:@""] || [_dicData[@"email"] isEqualToString:@"null"]) {
                
                self.headView.emailStr.text = @"暂未添加邮箱";
                
            }else{
                self.headView.emailStr.text = _dicData[@"email"];
            }
            
            self.dataArr = _dicData[@"work"];
            self.educationArr = _dicData[@"education"];
            hobbyArr = [[self.dicData[@"hobby"] componentsSeparatedByString:@","] copy];
            CGSize nameSize = [self.headView.nameStr sizeThatFits:CGSizeMake(MAXFLOAT, 20)];
            if (self.headView.nameConstraint.constant == 220) {
                if (nameSize.width > 192) {
                    self.headView.nameConstraint.constant -= 192;
                }else{
                    self.headView.nameConstraint.constant -= nameSize.width;
                }
            }
            
            CGSize nameSizeCon = [self.headView.nameStr sizeThatFits:CGSizeMake(192, MAXFLOAT)];
            self.headView.frame = CGRectMake(0, 0, screenW, self.headView.height - self.headView.nameStr.height + nameSizeCon.height);
            self.tableView.tableHeaderView = self.headView;
            [self.tableView reloadData];
            
            
            self.tableView.contentSize = CGSizeMake(0, self.tableView.contentSize.height + 20);
            
            [self.headView.imgBtn addTarget:self action:@selector(clickHeadImg) forControlEvents:UIControlEventTouchUpInside];
            
        }else {

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

       [self showSingleIconBubble:error.localizedDescription];
    }];

}

-(void)sendRequest{
    NSMutableDictionary * dic = [NSMutableDictionary  dictionary];
    
    //    if ([self.userId isEqualToString:allConstMemberid]) {
    //
    //        dic[@"userId"] = @"";
    //
    //    }else{
    
    dic[@"userId"] = allConstMemberid;
    
    //    }
    dic[@"TagerUserId"] = [USER_DEFAULTS objectForKey:@"userid"];
    
    dic[@"page"] = @(1);

    [LSHttpTool sendHttpData:@"getCibdList_app_cibd.im" params:dic success:^(id responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        //
        //        NSString * jsonStr = [LSHttpTool DataTOjsonString:dicInfo];
        //        NSLog(@"--------------------json:%@",jsonStr);
        
        
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            
            pageDict = dicInfo[@"data"][@"page"];
            dataArr = dicInfo[@"data"][@"record"];
            [self.tableView reloadData];
            
        }else{
            
        }
        
    } failure:^(NSError *error) {

        [self showSingleIconBubble:@"网络连接错误"];
        
    }];
    
}

#pragma mark - jump
-(void)jumpClass{
    
    FriendViewController * FriendView = [[FriendViewController alloc]init];
    FriendView.TagerUserId = [USER_DEFAULTS objectForKey:@"userid"];
    [self.navigationController pushViewController:FriendView animated:YES];
    
}
-(void)clickHeadImg{
    
    NSMutableArray *photos = [NSMutableArray array];
    MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
    MJPhoto *photo = [[MJPhoto alloc] init];
    photo.url = [NSURL URLWithString:_dicData[@"headPhoto"]];
    photo.srcImageView = self.headView.imgStr;
    [photos addObject:photo];
    browser.photos = photos;

    [browser show];

}
@end
